package com.qf.lanzhou.blog.api.service.impl;

import com.qf.lanzhou.blog.api.dao.Impl.NotificationDaoImpl;
import com.qf.lanzhou.blog.api.dao.NotificationDao;
import com.qf.lanzhou.blog.api.pojo.entity.Notification;
import com.qf.lanzhou.blog.api.pojo.entity.Page;
import com.qf.lanzhou.blog.api.service.NotificationService;

import java.util.List;

/**
 * @author 是柠檬甜
 * @ClassName NotificationServiceImpl
 * @description 通知服务层接口实现类
 * @date 2020/12/16 10:12
 * @modifier 是柠檬甜
 * @date 2020-12-16 10:12
 * @Version V1.0
 */
public class NotificationServiceImpl implements NotificationService {
    private NotificationDao notificationDao=new NotificationDaoImpl();
    @Override
    public List showAll() {
        List<Notification> list = notificationDao.selectAll();
        return list;
    }

    @Override
    public List show() {
        List<Notification> listPublic = notificationDao.select();
        return listPublic;
    }

    @Override
    public Boolean change(Long id1,Long id2) {
        Boolean status = notificationDao.updateAll();
        Boolean updateStatus1 = notificationDao.update(id1);
        Boolean updateStatus2 = notificationDao.update(id2);
        if (!status&&updateStatus1&&updateStatus2){
            throw new RuntimeException("系统繁忙，发布失败");
        }
        return true;
    }

    @Override
    public Boolean addNotification(String userName, String content) {
        Boolean insert = notificationDao.insert(userName, content);
        if(!insert){
            throw new RuntimeException("系统繁忙，添加失败");
        }
        return true;
    }

    @Override
    public List selectPage(Integer integer) {
        Page page = new Page(integer);
        List list = notificationDao.selectPage(page);
        return list;
    }

    @Override
    public Integer getCount() {
        Long aLong = notificationDao.selectCount();
        String s = Long.toString(aLong);
        Integer integer = Integer.decode(s);
        return integer;
    }

}
